package net.studou.bean.tools;

import java.util.HashMap;
import java.util.Map;

import net.studou.convert.BasicConvert;
import net.studou.exception.SystemException;

public class Properties {

	private Map<String, IConvert> propertyMap = new HashMap<String, IConvert>(); // key=source:target,value=Iconvert
	private BasicConvert basicConvert = new BasicConvert();

	public Properties(String sourceProperties) {
		String[] props = sourceProperties.split(",");
		for (String property : props) {
			property = property.trim();
			propertyMap.put(property + ":" + property, basicConvert);
		}
	}

	public Properties(String sourceProperties, String targetProperties)  {
		String[] sProps = sourceProperties.split(",");
		String[] tProps = targetProperties.split(",");
		if (sProps.length != tProps.length) {
			throw new SystemException("SourceProperty, targetProperty is not same");
		}
		for (int i = 0; i < sProps.length; i++) {
			String sProp = sProps[i].trim();
			String tProp = tProps[i].trim();
			String key = sProp + ":" + tProp;

			propertyMap.put(key, basicConvert);
		}
	}

	public Map<String, IConvert> getPropertyMap() {
		return propertyMap;
	}

	public void addPropertyMap(String sProp, String tProp) {
		propertyMap.put(sProp + ":" + tProp, basicConvert);
	}

	public void setConvert(String propertyPair, IConvert convert) {
		propertyMap.put(propertyPair, convert);
	}

}
